TYPE CASTING:
Converting from one data type to another is type casting.
Types:
Implicit conversion: it is automatically converted by the compiler itself
Explicit conversion: It should be converted by the user/programmer.
#include<stdio.h>
CONTROL STRUCTURES
Control Structures are just a way to specify the flow of control in programs.
There are three basic types of flow of control, known as
Sequence logic, or sequential flow
Selection logic, or conditional flow
Iteration logic, or repetitive flow
Sequence Logic
Sequential logic as the name suggests follows a serial or sequential flow in which the flow depends on the series of instructions given to the computer.
2. Selection Logic (Branching)
Selection Logic simply involves a number of conditions which decide one out of several written statements.
3. Iteration Logic (Looping)
It helps to repeat a statement a certain number of times until the condition is satisfied.
Selection Logic (Branching)
Selection Logic simply involves a number of conditions which decide one out of several written statements.
If statement
If…else statement
If… else if statement
Switch Statement
if statement
Use the if statement to specify a block of C code to be executed if a condition is true.
Syntax
if (condition)
{
// block the code to be executed if the condition is true
}
if… else statement
Use the if statement to specify a block of C code to be executed if a condition is true.
Use the other statement to specify a block of code to be executed if the condition is false.
Syntax
if (condition)
{
// block the code to be executed if the condition is true
}
else
{
// block of code to be executed if the condition is false
}
If… else if statement
Use the else if statement to specify a new condition if the first condition is false.
Syntax
if (condition1)
{
// block of code to be executed if condition1 is true
}
else if (condition2)
{
// block of code to be executed if the condition1 is false and condition2 is true
}
else
{
// block of code to be executed if the condition1 is false and condition2 is false
}
Switch Case Statement
Use the switch statement to select one of the many code blocks to be executed.
Syntax:
switch(expression)
{
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
This is how it works:
The switch expression is evaluated once
The value of the expression is compared with the values of each case
If there is a match, the associated block of code is executed
0 Comments